<?php

namespace app\adminapi\controller\system;

use app\adminapi\service\SysMenuService;
use app\adminapi\service\SysRoleService;
use app\adminapi\validate\SysRoleValidate;
use app\adminapi\validate\SystemMenuValidate;
use app\common\controller\BaseAdminController;

class SysRoleController extends BaseAdminController
{
    public array $notNeedLogin = [];

    public function list()
    {
        $params = (new SysRoleValidate())->get()->goCheck('list');
        $list = (new SysRoleService())->list($params);
        return app('json')->successWithData($list);
    }

    /**
     * @title   新增角色
     * @businessType    INSERT
     */
    public function insert()
    {
        $params = (new SysRoleValidate())->post()->goCheck('insert');
        (new SysRoleService())->addSysRole($params);
        return app('json')->success();
    }

    /**
     * @title   删除角色
     * @businessType    DELETE
     */
    public function delete()
    {
        $params = (new SysRoleValidate())->delete()->goCheck('delete');
        $result = (new SysRoleService())->deleteSysRole($params['roleId']);
        return app('json')->successWithData($result);
    }

    public function query()
    {
        $params = (new SysRoleValidate())->get()->goCheck('query');
        $result = (new SysRoleService())->getSysRole($params['roleId']);
        return app('json')->successWithData($result);
    }

    /**
     * @title   更新角色
     * @businessType    UPDATE
     */
    public function update()
    {
        $params = (new SysRoleValidate())->put()->goCheck('update');
        $result = (new SysRoleService())->updateSysRole($params);
        return app('json')->successWithData($result);
    }
}